
export const customUploadVideo = function(that, callback = (res) => {}){
  uni.chooseVideo({
    count: 1,
    sourceType: ['camera'],
    success: res => {
      console.log('开始录制视频返回', res.tempFilePath)
      // this.videoPath = res.tempFilePath;
      callback({
        code: 200,
        data: res.tempFilePath
      })
      getTempFilePath(res.tempFilePath, 'videoTempPath');
    },
    fail: (err) => {
      uni.getSetting({
        success: (res) => {
          let authStatus = res.authSetting['scope.camera'];
          if (!authStatus) {
            uni.showModal({
              title: '授权失败',
              content: 'Hello uni-app需要从您的相机获取视频，请在设置界面打开相关权限',
              success: (res) => {
                if (res.confirm) {
                  uni.openSetting()
                }
              }
            })
          }
        }
      })
    }
  });
}

const getTempFilePath = function(url, types) {
  uni.showLoading({
    title: '保存中...'
  });
  // 如果已经下载本地路径，那么直接储存
  let obj = {
    filePath: url,
    success: () => {
      uni.showModal({
        content: '保存成功',
        showCancel: false
      });
      uni.hideLoading();
    },
    fail: e => {
      uni.hideLoading();
      uni.showModal({
        content: '保存失败',
        showCancel: false
      });
    }
  };
  
  if (types === 'videoTempPath') {
    uni.saveVideoToPhotosAlbum(obj);
  } else {
    uni.saveImageToPhotosAlbum(obj);
  }
}